<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"> 
<h:head>

</h:head> 
<body onload="redirect();">  
	
<p:layout   fullPage="true">  
  
    <p:layoutUnit position="north" size="120" style =" text-align : center;"  > 
       <style type="text/css">
        .ui-widget{font-size:90% !important;}  
       </style> 
       <p:graphicImage id="logo" value="logo.jpg" style=" height:100px;"/>
  
    </p:layoutUnit>  
  
     <p:layoutUnit position="south" size="50"  resizable="false" closable="false" collapsible="false">  
       <h:form style =" text-align : center;">
        <h:outputText id="owner" value="Marcello Felappi, Selenia Vincenza Rusalen, Giovanni Battista Conserva" />  
        </h:form>
    </p:layoutUnit>  
  
   <p:layoutUnit position="center" size="600">  
      
     <script type="text/javascript">
    function redirect() {
		
		if(document.getElementById("employeeCheck").value=="true")
      	window.location = "http://localhost:8080/TravelDreamFelConRusWeb/employee/employeehome.xhtml";
		if(document.getElementById("customerCheck").value=="true")
	     window.location = "http://localhost:8080/TravelDreamFelConRusWeb/customer/customerhome.xhtml";


		
    }
  </script>
  
    <h:inputHidden  id="employeeCheck" 
                  value="#{auth.userEmployee}"/>
       <h:inputHidden  id="customerCheck" 
                  value="#{auth.userCustomer}"/>
    
   	 <h:form id="welcomeEmployee" style =" text-align : center;" rendered="#{auth.userEmployee}">
	       
            <p:outputLabel value="Benvenuto, impiegato" ></p:outputLabel><br/>
             <p:outputLabel value="Vai alla tua area personale" ></p:outputLabel><br/>
            <p:button outcome="employee/employeehome" value="Pagina Personale"  icon="ui-icon-arrowrefresh-1-w" ></p:button> 
            <p:commandButton action="#{logoutBean.logout}" value="Logout" />
    
			
	      </h:form>
	       <h:form id="welcomeCustomer" style =" text-align : center;" rendered="#{auth.userCustomer}">
	       
            <p:outputLabel value="Benvenuto, cliente" ></p:outputLabel><br/>
             <p:outputLabel value="Vai alla tua area personale" ></p:outputLabel><br/>
            <p:button outcome="customer/customerhome" value="Pagina Personale"  icon="ui-icon-arrowrefresh-1-w" ></p:button> 
            <p:commandButton action="#{logoutBean.logout}" value="Logout" />
    		
	      </h:form>
    
         <h:form id="signupForm" styleClass="input-form" rendered="#{auth.userNone}">
		<p:panel header="Registrazione" id="panel">
	<h:panelGrid columns="2">
	    <p:outputLabel value="Username" for="username" />
		<p:inputText id="username" label="Username"
			value="#{auth.username}"
				required="true" />
	
	
		<p:outputLabel value="Nome" for="firstname" />
		<p:inputText id="firstname" label="First Name"
			value="#{auth.firstName}"
				required="true" />
		<p:outputLabel value="Cognome" for="lastname" />
		<p:inputText id="lastname" label="Last Name"
			value="#{auth.lastName}"
				required="true" />
		
		<p:outputLabel value="Email" for="email" />
		
		<p:inputText id="email" required="true" label="email" 
		requiredMessage="Please enter your email address."
		validatorMessage="Invalid email format"
		value="#{auth.email}">
 
	  	<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
 
		</p:inputText>
		
		
		<p:outputLabel value="Password" for="password" />
		<p:password id="password" label="Password"
			value="#{auth.password}"
			feedback="true" required="true" match="password2" />
		<p:outputLabel value="Confirm" for="password2" />
		<p:password id="password2" label="Password"
			value="#{auth.password}"
			feedback="false" required="true" />
		<p:outputLabel value="Data di nascita" for="birthdate" />
		<p:calendar id="birthdate" value="#{auth.birthdate}" 
			navigator="true" required="true" yearRange="c-100:c-0"
			pattern="MM/dd/yyyy" showOn="button" readonlyInput="true"/>
		<h:outputText value="" />
		
	<h:panelGroup>
		 
		<p:selectBooleanCheckbox  id="check"
      			 value="#{auth.checked}"
               onchange="toggle('#{requestScope.foo.clientId}'); return false;" />
      
      
      <p:outputLabel value="Impiegato" for="check" />  
       
      
		</h:panelGroup>
		 <p:watermark for="code" value="Codice impiegato *" />
      <p:inputText label="Codice"
			value="#{auth.code}"
      	binding="#{requestScope.foo}" id="code" style="display: none" />
    	<script type="text/javascript">
      	function toggle(id) {
        var element = document.getElementById(id);
        
        if(element.style.display == 'block') {
          element.style.display = 'none';
        } else {
          element.style.display = 'block'
        }
      }
        </script>	
        
	
		
        
      	<h:panelGroup>
		<p:selectBooleanCheckbox required="true" id="terms"
			label="Accept terms and conditions"
			value="#{auth.acceptedTerms}"
			widgetVar="termsCheckbox" 
			  />
      
		<p:outputLabel value="Accetto i termini e le condizioni d'uso."
			onclick="termsCheckbox.toggle()" for="terms" />
	</h:panelGroup>
      
  
	
	
		<p:commandButton value="Registrati"
		action="#{auth.signUp}"
		style="display:block; margin:0 auto;"
		ajax="false" />
	</h:panelGrid>
	
		</p:panel>

	</h:form>			
	
    </p:layoutUnit>  
  
  
   <p:layoutUnit position="west" size="200" header="Pagine utili" resizable="false" closable="false" collapsible="false">   
            <p:menu>  
               
                     <p:menuitem value="Pacchetti" url="http://localhost:8080/TravelDreamFelConRusWeb/allPackages.xhtml" />  
                     <p:menuitem value="Promozioni" url="http://localhost:8080/TravelDreamFelConRusWeb/promotions.xhtml" />                    
          
            </p:menu>   
        </p:layoutUnit>  
       
  
    <p:layoutUnit position="east" size="400"  resizable="false" closable="false" collapsible="false" rendered="#{auth.userNone}">  
      
       <h:form id="login"
			onsubmit="document.getElementById('login').action='j_security_check';"
			prependId="false">
		<p:panel header="Login" id="panelLogin">
		<h:panelGrid columns="2">
	
		<p:outputLabel for="j_username" value="Username" />
		<p:inputText id="j_username" name="j_username" required="true" />
		
		<p:outputLabel for="j_password" value="Password" />
		<p:password id="j_password" name="j_password" />
		<p:commandButton id="submit" value="Login" ajax="false" />		
		
		
	</h:panelGrid>
	
		</p:panel>

	</h:form> 
	
       <h:form id="gift"
			action = "todo">
		<p:panel header="Vuoi fare un regalo?" id="panelGift">
		<h:panelGrid columns="1">
	
		<p:outputLabel for="gift"   value="Inserisci qui il tuo codice giftlist"   />
		<p:inputText id="gift" name="j_username" required="true" value="#{giftList.code}" />	
		<p:commandButton id="submit" value="Invia codice" action="#{giftList.checkCode()}" />
		
		</h:panelGrid>
	
		</p:panel>

	</h:form> 
       
         <h:form id="join"
			action = "todo">
		<p:panel header="Vuoi viaggiare con un amico?" id="panelFriend">
		<h:panelGrid columns="1">
	
		  <p:outputLabel for="friend"   value="Inserisci qui il tuo codice amico"   />
		  <p:inputText id="friend" name="j_username" required="true" value="#{friendManagement.friendCode}"/>
			
		  <p:commandButton id="submitFriendCode" action="#{friendManagement.checkFriendCode}" value="Invia codice" ajax="false" />		
		
		</h:panelGrid>
		</p:panel>
	</h:form> 
    
    </p:layoutUnit>  
  
   
  
</p:layout>  		
	
<p:growl id="growl" showDetail="true" life="5000" />
         
</body> 
</html>